<!--{include(pe_tpl('header_dialog.html'));}-->
<iframe id="mapPage" width="100%" height="540" frameborder="0" src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&coord={$_g_location}&key=GS2BZ-C5Q35-7LDI7-QFIU6-HF6ME-X4BNB&referer=择林鸟"></iframe>
<div class="tixing" style="background:#fef7ea;padding-left:15px">
	<div class="fl mat5">已选定地址：<span id="address"></span>，坐标：<span id="location"></span></div>
	<input type="button" value="设置为商户地址" class="tag_blue mal10 fr" onclick="button()" />
	<div class="clear"></div>
</div>
<script type="text/javascript">
$(function(){
	$("#address").html('{$_g_address}');
	$("#location").html('{$_g_location}');
})

window.addEventListener('message', function(event) {
    // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
    var loc = event.data;
    if (loc && loc.module == 'locationPicker') {//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
		$("#address").html(loc.poiaddress);
		$("#location").html(loc.latlng.lat + ',' + loc.latlng.lng);
		//pe_tip('当前坐标：' + loc.latlng.lat + ',' + loc.latlng.lng + '，已自动填入表单，可以关闭地图了！', 'success');
    }
}, false);

function button() {
	if ('{$_g_iframe}' != '') {
		$(":input[name='info[mendian_address]']", window.parent.frames['layui-layer-iframe{$_g_iframe}'].document).val($("#address").html());	
		$(":input[name='info[mendian_location]']", window.parent.frames['layui-layer-iframe{$_g_iframe}'].document).val($("#location").html());	
	}
	else {
		$(":input[name='info[mendian_address]']", window.parent.document).val($("#address").html());	
		$(":input[name='info[mendian_location]']", window.parent.document).val($("#location").html());	
	}
	pe_tip('地址：'+$("#address").html()+'，已自动填入表单，可以关闭地图了！', 'success');
	setTimeout(function(){
		parent.layer.close(parent.layer.getFrameIndex(window.name));	
	}, 800)
}
</script>
<script type="text/javascript" src="{$pe['host']}include/plugin/layer/layer.js"></script>
<!--{include(pe_tpl('footer_dialog.html'));}-->